package com.neusoft.tijian.controller;

import com.neusoft.tijian.po.CiDetailedReport;
import com.neusoft.tijian.po.CiReport;
import com.neusoft.tijian.service.CiReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ciReport") // 确保与前端baseURL匹配
public class CiReportController {

    @Autowired
    private CiReportService ciReportService;

    // 查询体检报告
    @PostMapping("/listCiReport")
    public List<CiReport> listCiReport(@RequestBody Map<String, Integer> params) {
        return ciReportService.listCiReportByOrderId(params.get("orderId"));
    }

    // 批量更新检查项明细
    @PostMapping("/updateCiDetailedReport")
    public Integer updateCiDetailedReport(@RequestBody List<CiDetailedReport> list) {
        return ciReportService.batchUpdateCiDetailedReport(list);
    }

    // 生成报告模板
    @PostMapping("/createReportTemplate")
    public Integer createReportTemplate(@RequestBody Map<String, Integer> params) {
        // 调用服务层方法，成功返回1，失败返回0
        boolean result = ciReportService.createReportTemplate(
                params.get("orderId"),
                params.get("smId")
        );
        return result ? 1 : 0;
    }
}
